package com.mhyx;

import com.alibaba.nacos.api.config.ConfigType;
import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource;
import com.mhyx.pojo.TestNacosSetting;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 *
 * @User: c.c
 * @Date: 2022/6/17
 * @Time: 14:33
 * @Description:
 */
@SpringBootApplication
//@NacosPropertySource(dataId = "nacos-configuration", type = ConfigType.YAML)
public class Application {
  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }

  //约等于单独写个class类
  @Component
  public class testimpl implements CommandLineRunner{

    private final Logger logger = LoggerFactory.getLogger(getClass());

//    直接读取nacos方法
    @Autowired
    private TestNacosSetting setting;
    public void run(String... args) throws Exception {
      logger.info("User的id为："+setting.getId());
      logger.info("User的name为："+setting.getNames());
      logger.info("User的age为："+setting.getAge());
      logger.info("User的paytime为："+setting.getPayTimeOut());
    }
  }

  @Component
  public class ValueCommandLineRunner implements CommandLineRunner {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    //        @NacosValue(value = "${order.pay-timeout-seconds}")
    @Value(value = "${user.id}")
    private String id;

    //        @NacosValue(value = "${order.create-frequency-seconds}")
    @Value(value = "${user.names}")
    private String name;

    @Override
    public void run(String... args) {
      logger.info("User的id为:" + id);
      logger.info("User的name为:" + name);
    }
  }
}
